package com.demo.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.appbase.custom.constant.CommonConstants;
import com.demo.helper.BatteryHelper;
import com.module.commonui.R;
import com.tange.base.toolkit.PreferenceUtil;
import com.tange.base.toolkit.StringUtils;
import com.tg.appcommon.android.ResourcesUtil;
import com.tg.appcommon.android.TGLog;

public class PlayerTopInfoView extends LinearLayout {
    private ImageView ivBattery;
    private TextView tvRecording, tvSpeed, signal, frameRate;


    public PlayerTopInfoView(Context context) {
        super(context);
        initContentView(context);
    }

    public PlayerTopInfoView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PlayerTopInfoView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initContentView(context);
    }

    public void initContentView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.player_top_show_info, this);
        ivBattery = view.findViewById(R.id.iv_battery);
        tvRecording = view.findViewById(R.id.tv_recording);
        tvSpeed = view.findViewById(R.id.tv_speed);
        signal = view.findViewById(R.id.tv_signal);
        frameRate = view.findViewById(R.id.tv_rate);
    }

    public ImageView getBattery(){
        return ivBattery;
    }

    public void showBattery(boolean show){
        ivBattery.setVisibility(show? VISIBLE : GONE);
    }
    public void setBattery(int battery, int mode){
        BatteryHelper.setBattery(ivBattery, mode, battery, false);
    }

    public TextView getSignalView(){
        return signal;
    }

    public TextView getSpeedView(){
        return tvSpeed;
    }

    public void showSignalView(boolean show){
        signal.setVisibility(show? VISIBLE : GONE);
    }
    public void setSpeed(String text){
        tvSpeed.setText(text);
    }
    public TextView getFrameRateView(){
        return frameRate;
    }

    public TextView getRecording(){
        return tvRecording;
    }

    public void setFrameRate(String text){
        frameRate.setText(text);
    }

    public void showUI(String uuid, boolean first){
        if (first){
            tvSpeed.setText("64KB");
            frameRate.setText(ResourcesUtil.getString(R.string.setting_frame_rate) + ":12");
        }else{
            if (!StringUtils.isEmpty(uuid)) {
                int userId = PreferenceUtil.getInt(getContext(), CommonConstants.PRE_USER_ID);
                boolean checked1 = PreferenceUtil.getBoolean(getContext(), CommonConstants.PRE_SETTINGS_BITRATE_UUID + uuid + userId);
                boolean checked2 = PreferenceUtil.getBoolean(getContext(), CommonConstants.PRE_SETTINGS_SIGNAL_UUID + uuid + userId);
                boolean checked3 = PreferenceUtil.getBoolean(getContext(), CommonConstants.PRE_SETTINGS_FRAME_RATE_UUID + uuid + userId);

                TGLog.d("ACCameraPlayerView", "checked2 = " + checked2);
                tvSpeed.setVisibility(checked1? View.VISIBLE : View.GONE);
                signal.setVisibility(checked2? View.VISIBLE : View.GONE);
                frameRate.setVisibility(checked3? View.VISIBLE : View.GONE);
            }
        }
    }

    public void showView(String uuid, boolean show){
        if (show){
            if (!StringUtils.isEmpty(uuid)) {
                int userId = PreferenceUtil.getInt(getContext(), CommonConstants.PRE_USER_ID);
                boolean checked1 = PreferenceUtil.getBoolean(getContext(), CommonConstants.PRE_SETTINGS_BITRATE_UUID + uuid + userId);
                boolean checked2 = PreferenceUtil.getBoolean(getContext(), CommonConstants.PRE_SETTINGS_SIGNAL_UUID + uuid + userId);
                boolean checked3 = PreferenceUtil.getBoolean(getContext(), CommonConstants.PRE_SETTINGS_FRAME_RATE_UUID + uuid + userId);

                TGLog.d("ACCameraPlayerView", "checked2 = " + checked2);
                tvSpeed.setVisibility(checked1? View.VISIBLE : View.GONE);
                signal.setVisibility(checked2? View.VISIBLE : View.GONE);
                frameRate.setVisibility(checked3? View.VISIBLE : View.GONE);
            }
        }else{
            tvRecording.setVisibility(GONE);
            ivBattery.setVisibility(GONE);
            tvSpeed.setVisibility(View.GONE);
            signal.setVisibility(View.GONE);
            frameRate.setVisibility(View.GONE);
        }

    }

}